package com.mtf.controller;

import java.util.Arrays;
import com.mtf.common.vo.Result;
import com.mtf.entity.MtfOrderDetail;
import com.mtf.service.IMtfOrderDetailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

 /**
 * @Description: mtf_order_detail
 * @Author: jeecg-boot
 * @Date:   2024-04-09
 * @Version: V1.0
 */
@Api(tags="mtf_order_detail")
@RestController
@RequestMapping("/orderDetail")
@Slf4j
public class MtfOrderDetailController {
	@Autowired
	private IMtfOrderDetailService mtfOrderDetailService;
	
	/**
	 *   添加
	 *
	 * @param mtfOrderDetail
	 * @return
	 */
	//@AutoLog(value = "mtf_order_detail-添加")
	@ApiOperation(value="mtf_order_detail-添加", notes="mtf_order_detail-添加")
	//@RequiresPermissions("com.usual:mtf_order_detail:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody MtfOrderDetail mtfOrderDetail) {
		mtfOrderDetailService.save(mtfOrderDetail);
		return Result.OK("添加成功！");
	}
	
	/**
	 *  编辑
	 *
	 * @param mtfOrderDetail
	 * @return
	 */
	//@AutoLog(value = "mtf_order_detail-编辑")
	@ApiOperation(value="mtf_order_detail-编辑", notes="mtf_order_detail-编辑")
	//@RequiresPermissions("com.usual:mtf_order_detail:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody MtfOrderDetail mtfOrderDetail) {
		mtfOrderDetailService.updateById(mtfOrderDetail);
		return Result.OK("编辑成功!");
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "mtf_order_detail-通过id删除")
	@ApiOperation(value="mtf_order_detail-通过id删除", notes="mtf_order_detail-通过id删除")
	//@RequiresPermissions("com.usual:mtf_order_detail:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		mtfOrderDetailService.removeById(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	//@AutoLog(value = "mtf_order_detail-批量删除")
	@ApiOperation(value="mtf_order_detail-批量删除", notes="mtf_order_detail-批量删除")
	//@RequiresPermissions("com.usual:mtf_order_detail:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		this.mtfOrderDetailService.removeByIds(Arrays.asList(ids.split(",")));
		return Result.OK("批量删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "mtf_order_detail-通过id查询")
	@ApiOperation(value="mtf_order_detail-通过id查询", notes="mtf_order_detail-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<MtfOrderDetail> queryById(@RequestParam(name="id",required=true) String id) {
		MtfOrderDetail mtfOrderDetail = mtfOrderDetailService.getById(id);
		if(mtfOrderDetail==null) {
			return Result.error("未找到对应数据");
		}
		return Result.OK(mtfOrderDetail);
	}

}
